using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Security.Cryptography;

namespace SecureLoginApp
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void btnLogin_Click(object sender, EventArgs e)
        {
            string ticket = "";
            localhost.LoginAuthentication proxy = new SecureLoginApp.localhost.LoginAuthentication();
            DateTime serverDate = proxy.GetServerDate();
            RSACryptoServiceProvider serverKey = new RSACryptoServiceProvider();
            serverKey.FromXmlString(proxy.GetKey());

            try
            {
                ticket = proxy.Login(new SecurityComp.ClientSecurity(serverKey).EncryptLoginData(txtUser.Text, txtPassword.Text, serverDate));
            }
            catch (Exception ex)
            {
            }

            if(ticket != String.Empty)
            {
                MessageBox.Show("You are loggin in as " + ticket + ".");
            }
            else
            {
                MessageBox.Show("Error loggin in.");
            }
        }
    }
}